package com.asianrapid.demo.controller;
import com.asianrapid.demo.asian_oa.model.EWorkLog;
import com.asianrapid.demo.asian_oa.service.EWorkLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.asianrapid.core.domain.AsianResult;
import com.asianrapid.core.utils.ResultUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by chijiaxin on 2018/07/10.
*/
@RestController
@RequestMapping("/e/work/log")
public class EWorkLogController {
    @Resource
    private EWorkLogService eWorkLogService;

    @PostMapping("/add")
    public AsianResult add(EWorkLog eWorkLog) {
        eWorkLogService.save(eWorkLog);
        return ResultUtils.success();
    }

    @DeleteMapping("/delete")
    public AsianResult delete(@RequestParam Integer id) {
        eWorkLogService.deleteById(id);
        return ResultUtils.success();
    }

    @PutMapping("/update")
    public AsianResult update(EWorkLog eWorkLog) {
        eWorkLogService.update(eWorkLog);
        return ResultUtils.success();
    }

    @GetMapping("/detail")
    public AsianResult detail(@RequestParam Integer id) {
        EWorkLog eWorkLog = eWorkLogService.findById(id);
        return ResultUtils.success(eWorkLog);
    }

    @GetMapping("/list")
    public AsianResult list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<EWorkLog> list = eWorkLogService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultUtils.success(pageInfo);
    }
}
